$(document).ready(function() {
    
});

function replaceAll(string, token, newtoken) {
    while (string.indexOf(token) != -1) {
        string = string.replace(token, newtoken);
    }
    return string;
}

function addNotify(mensg) {
    var atual = "not-" + $("#notific ul li").length;
    $("#notific ul").append("<li class='none notify-top' id='" + atual + "'></li>");
    $('#' + atual).load(BASE_URL + "mensagem/" + mensg, function() {
        $('#' + atual).effect('slide', {direction: "vertical", mode: "show", scale: "content"});
    });

    $(".notify-top").off();
    $(".notify-top").on("click", function() {
        removeNotify($(this).attr("id"));
    });

    setTimeout(function() {
        removeNotify(atual);
    }, 5000);
}

contHideNotif = 0;

function removeNotify(id) {
    if (contHideNotif == 0) {
        $('#' + id).effect('slide', {direction: "vertical", mode: "hide", scale: "content"}, function() {
           $('#' + id).remove();
        });
    }
    contHideNotif = 0;
}

function __validaForm() {
    $(".error").removeClass("error");
    $("a.required").removeClass("required");
    var tempValid = true;

    $(".required", $("#form")).each(function() {
        if (!$(this).val()) {
            $(this).addClass("error");
            tempValid = false;

            console.log($(this).val());
            if ($(this).is("select")) {
                $(this).next().addClass('error');
            }
        }
    });
    return tempValid;
}

